package net.piggy.common.util.general;

import java.lang.reflect.Field;

public class ReflectionUtil {
    public static Field getField(Object target, String fieldName) {
        if(target != null){
            for (Class<?> clazz = target.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
                Field[] declaredFields = clazz.getDeclaredFields();
                for(Field field : declaredFields){
                    if(field.getName().equals(fieldName)){
                        return field;
                    }
                }
            }
        }
        return null;
    }
}
